<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
<head>
	<title>当前预警信息</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<link rel="stylesheet" type="text/css" href="../../css/style.css">
	<script type="text/javascript" src="../../js/jquery-1.8.2.js"></script>
	<script type="text/javascript" src="../../js/dialog/jquery.artDialog.source.js?skin=default"></script>
	<script type="text/javascript" src="../../js/dialog/plugins/iframeTools.source.js"></script>
	<script type="text/javascript" src="../../js/jquery.ztree.all-3.5.min.js"></script>
	<script type="text/javascript" src="../../js/jquery.form.js"></script>
	<script type="text/javascript" src="../../js/jquery.page.js"></script>
	<script type="text/javascript" src="../../js/base.js"></script>
</head>
<body class="app">
	<div id="tips" class="tips"></div>
	<h3>当前预警信息</h3>
	<form class="search" name="search" action="dqyjxx_search.action" method="post">
		<div class="tbdiv">
		<table>
			<tr>
				<th width="100">行政监管单位：</th>
				<td width="100"><select name="adminCode"></select></td>
				<th width="100">物业公司：</th>
				<td width="100"><select name="propertyCode"></select></td>
				<th width="100">维保单位：</th>
				<td><select name="serviceCode"></select></td>
			</tr>
			<tr>
				<th>预警类型：</th>
				<td><select name="warningType" style="width:75px;"></select></td>
				<th>电梯ID：</th>
				<td colspan="3"><input type="text" class="inputText" name="eleCode" value="" style="width:110px;"/></td>
			</tr>
			<tr>
				<th>所属区域：</th>
				<td colspan="4">
					<input type="hidden" name="areaName" value=""/>
					<input type="text" class="inputText" name="areaNameN" value="" style="width:347px;*width:348px;cursor:pointer;" readonly="readonly" />
				</td>
				<td><input type="submit" value="查询" class="inputButton"/></td>
			</tr>
		</table>
		</div>
	</form>
	<div id="list"></div>
	<div class="areaTree"><div id="areaTree" class="ztree"></div></div>
	
	<div id="view" style="width:650px;display:none;">
		<form name="viewForm" id="viewForm">
		<dl class="view">
			<dt>电梯号码：</dt>
			<dd class="giant"><label name="eleCode"></label></dd>
			<dt>电梯名称：</dt>
			<dd class="giant"><label name="eleName"></label></dd>
			<dt>注册代码：</dt>
			<dd class="giant"><label name="eleBasicRegNum"></label></dd>
			<dt>电梯运行次数超限：</dt>
			<dd class="giant"><font class="contrast" ><label name="eleCirculateTimeCount"></label></font>(<label name="eleSumTime"></label>)</dd>
			<dt>门机运行次数超限：</dt>
			<dd class="giant"><font class="contrast" ><label name="doorCirculateTimeCount"></label></font>(<label name="doorSumTime"></label>)</dd>
			<dt>制动器运行次数超限：</dt>
			<dd class="giant"><font class="contrast" ><label name="detentCirculateTimeCount"></label></font>(<label name="detentSumTime"></label>)</dd>
			<dt>主接触器运行次数超限：</dt>
			<dd class="giant"><font class="contrast" ><label name="mainContactCirTimeCount"></label></font>(<label name="mainContactSumTime"></label>)</dd>
			<dt>辅助接触器运行次数超限：</dt>
			<dd class="giant"><font class="contrast" ><label name="runContactCirTimeCount"></label></font>(<label name="runContactSumTime"></label>)</dd>
			<dt>钢丝绳折弯次数超限：</dt>
			<dd class="giant"><font class="contrast" ><label name="wireBendCirTimeCount"></label></font>(<label name="wireBendSumTime"></label>)</dd>
			<dt>过期未年检：</dt>
			<dd class="giant"><font class="dtc">计划年检时间<label name="checkTime"></label></font></dd>
			<dt>过期未维保：</dt>
			<dd class="giant"><font class="dtc">计划维保时间<label name="serviceTime"></label></font></dd>

			
			<dt>行政监管单位：</dt>
			<dd class="giant"><label name="adminName"></label> - 单位电话：<label name="adminPhone"></label></dd>
			<dt>物业单位：</dt>
			<dd class="giant"><label name="propertyName"></label> - 单位电话：<label name="propertyPhone"></label></dd>
			<dt>维保单位：</dt>
			<dd class="giant"><label name="serviceName"></label> - 单位电话：<label name="servicePhone"></label></dd>
			<div class="cl"></div>
		</dl>
		</form>
	</div>
	<script type="text/javascript">
	setInterval("rlist()",10000);
	var rlist = function(){
		$('#list').page('show');
	}
	var view = function(row){
		$.dialog({
			id:'viewdialog',
			title:'信息查看-当前预警信息',
			lock:true,
			width:'100%',
			height:'100%',
			content:document.getElementById('view')
		});
		$('#viewForm').json2form(row);
		contrast();
	}
	var contrast = function(){
		var $fonts = $('#viewForm').find('.contrast');
		var $dtcs = $('#viewForm').find('.dtc');
		$fonts.each(function(i,n){
			var $label = $(n).next(); 
			if($label.text() <= $(n).text()){
				$(n).attr('color','red');
			}
		});
		$dtcs.each(function(i,n){
			var ct = new Date($(n).children('label').text());
			var now = new Date();
			if(now >= ct){
				$(n).attr('color','red');
			}
		});
	}
	$(function(){
		$('#list').page({
			url:'dqyjxx_search.action',
			config:'pageinfo,record,first,last,next,prev,jump',
			items:[{
				title:'电梯号码',
				name:'eleCode'
			},{
				title:'电梯名称',
				name:'eleName'
			},{
				title:'预警内容',
				name:'earlyWarning',
				irender:function(row){
					var text = getWarning(row.earlyWarning);
					var $span = $('<span style="cursor:default;">'+cutString(text,36)+'</span>');
					var $tips = $('#tips');
					$span.mouseover(function(){
						$tips.html(text);
						$tips.show();
					}).mousemove(function(e){
						$tips.offset({top:e.pageY,left:e.pageX+20});
					}).mouseout(function(){
						$tips.empty();
						$tips.offset({top:0,left:0});
						//$tips.css({top:0,left:0});
						$tips.hide();
					});
					return $span;
				}
			},{
				title:'详情',
				render:function(row){
					$a = $('<a href="javascript:void(0)")">【详细】</a>');
					$a.click(function(){
						view(row);
					});
					return $a;
				}
			}]
		});

		$(document.search).ajaxForm({
			beforeSubmit:function(formData){
				var param = $(formData).formParam();
				$('#list').page('param',param);
				$('#list').page('show');
				return false;
			}
		});
		$('select[name=adminCode]').selectload('../../common/adminunit_select.action','adminCode','adminName');
		$('select[name=propertyCode]').selectload('../../common/propertyunit_select.action','propertyCode','propertyName');
		$('select[name=serviceCode]').selectload('../../common/serviceunit_select.action','serviceCode','serviceName');
		$('select[name=warningType]').selectload('../../common/code.action','code','codedesc',{codepid:'5'});
	});
	$(function(){
		$(document).mouseup(function(e){
			var $target = $(e.target);
			if(!$target.is('.areaTree')){
				if($target.parents('.areaTree').length == 0){
					$('.areaTree').hide();
				}
			}
		});
		
		//渲染区域树
		$.fn.zTree.init($('#areaTree'),{
			data: {
				key:{
					name:'areaname'
				},
				simpleData: {
					enable: true,
					idKey:'areacode',
					pIdKey:'parentcode',
					rootPId:0
				}
			},
			async: {
				enable: true,
				url:"../../common/area_tree.action",
				autoParam:["areacode"]
			},
			callback:{
				onClick:function(e,id,node){
					var oldnode = node;
					if(node.isParent == false){
						var $areaTree = $('.areaTree');
						var areaArr = new Array();
						areaArr.unshift(node.areaname);
						while(node.parentcode > 0){
							node = node.getParentNode();
							areaArr.unshift(node.areaname);
						}
						$('input[name=areaNameN]').val(areaArr.join(' > '));
						$('input[name=areaName]').val(oldnode.areacode);
						$areaTree.hide();
					}
				}
			}
		});
		
		//区域树
		$('input[name=areaNameN]').click(function(){
			$this = $(this);
			$hidden = $('input[name=areaName]');
			$areaTree = $('.areaTree');
			$this.val('');
			$hidden.val('');
			var os = $this.offset();
			$areaTree.css({left:os.left,top:os.top+($this.outerHeight(true)-1)});
			$areaTree.show();
		});
	});
	var getWarning = function(warningType){
		warningType = parseInt(warningType).toString(2);
	    var n = x = warningType.length - 1;
	    var f = new Array();
	    while(x >= 0){
		    if(warningType.substr(x,1) == '1'){
			    var t = '1';
			    for ( var i = n - x; i > 0; i--) {
					t+='0';
				}
				f.push(parseInt(t,2).toString(10));
		    }
		    x--;
	    }
	    var arr = new Array();
	    $.ajax({
		    url:'../../common/code.action',
		    type:'post',
		    async:false,
		    dataType:'json',
		    data:{code:f.join(','),codepid:'5'},
		    success:function(data){
			    $.each(data,function(i,n){
			    	arr.push(n.codedesc);
				});
			}
		});
		return arr.join(',');
	}
	/**
	 * 根据长度截取先使用字符串，超长部分追加...
	 * @param str 对象字符串
	 * @param len 目标字节长度
	 * @return 处理结果字符串
	 */
	function cutString(str, len) {
		//length属性读出来的汉字长度为1
		if(str.length*2 <= len) {
			return str;
		}
		var strlen = 0;
		var s = "";
		for(var i = 0;i < str.length; i++) {
			s = s + str.charAt(i);
			if (str.charCodeAt(i) > 128) {
				strlen = strlen + 2;
				if(strlen >= len){
					return s.substring(0,s.length-1) + "...";
				}
			} else {
				strlen = strlen + 1;
				if(strlen >= len){
					return s.substring(0,s.length-2) + "...";
				}
			}
		}
		return s;
	}
	</script>
</body>
</html>
